// Copyright (c) 2002 Cunningham & Cunningham, Inc.
// Released under the terms of the GNU General Public License version 2 or later.

package eg.music
{

import com.fit4as.fit.*;
import com.fit4as.util.reflect.ClassUtil;

public class Realtime extends TimedActionFixture {

    private var system : Simulator = Simulator.system;

    override public function time() : Date {
        return new Date(Simulator.time);
    }

    public function pause() : void {
        var seconds : Number = parseFloat(cells.more.text());
        system.delay(seconds);
    }

    public function await()  : void {
        systemCall("wait", cells.more);
    }

    public function fail()  : void {
        systemCall("fail", cells.more);
    }

    override public function enter()  : void {
        system.delay(0.8);
        super.enter();
    }

    override public function press()  : void {
        system.delay(1.2);
        super.press();
    }

    private function systemCall(prefix : String, cell : Parse)  : void {
        var method : String = camel(prefix + " " + cell.text());
        var empty : Array = [];
        try {
            ClassUtil.getMethod(ClassUtil.getClass(system), method, empty).invoke(system, empty);
        } catch (e : Exception) {
            exception(cell, e);
        }
    }
}
}